<template>
  <div class="home">
    <el-row :gutter="20">
      <el-col :span="6" v-for="(item, index) in cardInfo" :key="index">
        <div class="grid-content bg-purple">
          <Card :info="item" />
        </div>
      </el-col>
    </el-row>
    <div class="contain">
      <Charts :options="options" />
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
import Card from '@/components/Card/Card.vue'
import Charts from '@/components/Charts/Charts.vue'
import { getTotalData } from '@/api/order.js'

export default {
  name: 'Home',
  components: {
    Card,
    Charts
  },
  data() {
    return {
      cardInfo: [
        {
          icon: 'icon-zongdingdan',
          color: '#1296db',
          title: '总订单',
          count: '102,400'
        },
        {
          icon: 'icon-xiaoshoue',
          color: '#d4237a',
          title: '总销售额',
          count: '102,400'
        },
        {
          icon: 'icon-taocanxiaoshoubaobiao',
          color: '#1296db',
          title: '今日订单数',
          count: '102,400'
        },
        {
          icon: 'icon-xiaoshoue1',
          color: '#1afa29',
          title: '今日销售额',
          count: '102,400'
        }
      ],
      options: {}
    }
  },
  created() {
    this.init()
  },
  methods: {
    async init() {
      const { totalOrder, totalAmount, todayOrder, totayAmount, xData, orderData, amountData } = await getTotalData()
      // console.log(orderData)
      // header总金额等数据
      const arr = [totalOrder, totalAmount, todayOrder, totayAmount]
      arr.forEach((v, i) => {
        this.cardInfo[i].count = v
      })
      // 报表数据

      this.options = {
        title: {
          text: '数据统计'
        },
        tooltip: {
          trigger: 'axis'
        },
        legend: {
          data: ['订单', '销售额', '注册人数', '管理员人数']
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        xAxis: {
          type: 'category',
          boundaryGap: false,
          data: xData
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            name: '订单',
            type: 'line',
            stack: '总量',
            data: orderData
          },
          {
            name: '销售额',
            type: 'line',
            stack: '总量',
            data: amountData
          }
        ]
      }
      console.log(this.options)
    }
  }
}
</script>

<style scope>
.home {
  width: 100%;
  height: 100%;
}

.bg-purple {
  background: #fff;
}

.grid-content {
  height: 100px;
}
.contain {
  width: 100%;
  height: 360px;
  background: #fff;
  margin-top: 30px;
}
.home >>> .el-col {
  padding: 0 20px 0 0;
}
</style>
